/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.clarice.homechef.config;

import com.clarice.homechef.constants.Constants;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

/**
 *
 * @author Akshay Velhal
 */
@Configuration
public class DatabaseContextConfig {
    
    @Bean
    public DataSource dataSource() throws Exception {
        System.out.println("Creating Datasource");
        DataSource dataSource = null;
       	try{ 
            Class.forName("org.postgresql.Driver");
            dataSource = new DriverManagerDataSource(Constants.DB_CONNECTION_STRING, Constants.DB_USERNAME, Constants.DB_PASSWORD);
       	} catch (Exception ex) {
            System.out.println("Exception for ");
            throw new Exception("Unable to load JNDI Datasource", ex);
       	}
        System.out.println("returning Datasource");
        return dataSource;
    }
    
}
